/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dinfo.shirodemo;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

/**
 *
 * @author Administrator
 */
public class ShiroDemo {
    
    
    public static void main(String[] argv)
    {		// 获取SecurityManager 的工厂 此处用的ini
            Factory<org.apache.shiro.mgt.SecurityManager> factory =  new  IniSecurityManagerFactory("shiro.ini");
            // 得到SecurityManager 并且绑定到 SecurityUtils
            org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
            SecurityUtils.setSecurityManager(securityManager);
            
            Subject subject  =  SecurityUtils.getSubject();
            
            UsernamePasswordToken token = new UsernamePasswordToken("song", "12");
            
            try {
				subject.login(token);
			} catch (AuthenticationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            
            System.out.println(subject.isAuthenticated());
    }
    
    
}
